﻿
using Ls.Web.Framework.Permissions;
using Microsoft.AspNetCore.Mvc.Filters;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic; 

namespace Ls.Web.Api.Infrastructure
{
    /// <summary>
    /// 请求头Filter 接口文档 用
    /// </summary>
    public class HttpHeaderFilter : IOperationFilter
    {
        public void Apply(Operation operation, OperationFilterContext context)
        {
            if (operation.Parameters == null)
                operation.Parameters = new List<IParameter>();
            var attres = ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)context.ApiDescription.ActionDescriptor).MethodInfo.GetCustomAttributes(typeof(PermissionAttribute),true); //是否有验证用户标记

            if (attres.Length >0)
            {

                operation.Parameters.Add(new NonBodyParameter { Name = "Authorization", @In = "header", Description = "JWT Token（\"Bearer \"+ Token）", Required = false, Type = "string" });
            }

        }
    }
}
